//
//  MYTitleButton.m
//  奇闻
//
//  Created by 似水灵修 on 14-11-22.
//  Copyright (c) 2014年 MingYueGuCheng. All rights reserved.
//

#import "MYTitleButton.h"

@interface MYTitleButton ()
@property (nonatomic, weak) UIImage *curImage;
@end
@implementation MYTitleButton

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        //添加image,title,背景
        [self setNormalImage:@"navigationbar_arrow_down"];
        [self setSelectedImage:@"navigationbar_arrow_up"];
        [self setNormalTitleColor:[UIColor blackColor]];
        self.titleLabel.font = MYNavigationTitleFont;
        self.adjustsImageWhenHighlighted = NO;
        [self setResizedHighlightedBg:@"navigationbar_filter_background_highlighted"];
        [self sizeToFit];
        self.titleLabel.x = self.imageView.x;
        self.imageView.x = CGRectGetMaxX(self.titleLabel.frame);
        
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    if (self.curImage) {
        self.titleLabel.x = self.imageView.x;
        self.imageView.x = CGRectGetMaxX(self.titleLabel.frame);
    }
}
/*因为button也可能没有图片，所以需要分情况设置size*/
- (void)setImage:(UIImage *)image forState:(UIControlState)state
{
    [super setImage:image forState:state];
    _curImage = image;
    [self sizeToFit];
}
- (void)setTitle:(NSString *)title forState:(UIControlState)state
{
    [super setTitle:title forState:state];
    [self sizeToFit];
}
/**************************************/
@end
